//
//  ACWBaseVC.m
//  aichewang
//
//  Created by ucs on 16/2/23.
//  Copyright © 2016年 aichewang. All rights reserved.
//

#import "ACWBaseVC.h"
#import "UIViewController+BackButtonHandler.h"

@interface ACWBaseVC()<UIGestureRecognizerDelegate>
@end

@implementation ACWBaseVC

- (instancetype)initWithScrollView {
    if (self = [super init]) {
        _scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _scrollView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_scrollView];
        _autoHiddenKeyBoardEnable = NO;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (_autoHiddenKeyBoardEnable) {
        UITapGestureRecognizer *mullTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenKeyBoard:)];
        mullTap.delegate = self;
        mullTap.numberOfTapsRequired = 1;
        [self.view addGestureRecognizer:mullTap];
    }
}

- (void)hiddenKeyBoard:(UITapGestureRecognizer *)tap {
    [tap.view endEditing:YES];
}

- (void)pushNavControllerWithoutBottomBar:(UIViewController *)VC {
    [self.navigationController pushViewController:VC animated:YES];
    [self.tabBarController.tabBar setHidden:YES];
}

//重写这个方法获取导航栏返回按钮的Action事件
-(BOOL)navigationShouldPopOnBackButton {
    // 判断是否传过来的是根控制器
    if (self.navigationController.viewControllers.count == 2) {
        [self.tabBarController.tabBar setHidden:NO];
    }
    return YES;
}

#pragma mark ------------------------------------------------------------
#pragma mark UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    //由于ACWBaseVC添加了一个点击手势(用于点击空白处退出键盘),可能会导致其子视图的button或者其他手势事件失效，可以这里设置白名单
    //可以打印[touch.view class]，获得类名，然后加进if判断
    //NSLog(@"%@", [touch.view class]);
    if ([[NSString stringWithFormat:@"%@",[touch.view class]] isEqualToString:@"UITableViewCellContentView"]) {
        return NO;
    } else return YES;
}

@end
